package cn.edu.scau.cmi.huangxiaodong.client;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import cn.edu.scau.cmi.huangxiaodong.mybatis.dao.StudentMapper;
import cn.edu.scau.cmi.huangxiaodong.mybatis.entity.Student;

public class MybatisClient {

	public static void main(String[] args) {

		InputStream in=null;
		try {
			in = Resources.getResourceAsStream("mybatis-config.xml");
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		SqlSessionFactory factory = builder.build(in);
		//开启自动提交事务
		SqlSession session=factory.openSession(true);
		StudentMapper studentMapper=session.getMapper(StudentMapper.class);
		Student student=new Student();
		student.setName("huang");
		student.setNumber(123L);
		student.setTutor(456L);
		System.out.println(studentMapper.saveStudent(student));
		System.out.println(studentMapper.listStudentEntitys());
		
	}
}

